Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
User-defined functions
As you have already seen in the previous chapter’s discussion of
INTERNAL-ENTRIESand theGET-SIGNATUREmethod, there is an alternative to the internal procedure as a named entry point within a procedure file. This is the user-defined function, sometimes referred to as a UDF or simply as a function. You are probably familiar with functions from other programming languages. Fundamentally, a function differs from a procedure in that it returns a value of a specific data type, and therefore can act in place of any other kind of variable or expression that would evaluate to the same data type. This means that you can place functions inside other expressions within a statement or within theWHEREclause of a result set definition. By contrast, you must invoke a procedure, whether external or internal, with aRUNstatement. If it needs to return information, you have to useOUTPUTparameters that your code examines after the procedure returns. You should therefore consider defining a function within your application for a named entry point that needs to return a single value and that is convenient to use within larger expressions.You can also compare user-defined functions with the many built-in functions that are a part of the Progress 4GL, such as
NUM-ENTRIES,ENTRY, and many others that you’ve seen and used. Your functions can provide the same kinds of widely useful behavior as the built-in functions, but specific to your application.If you use a function in a
WHEREclause or other expression in the header of aFOR EACHblock, Progress evaluates the function once, at the time the query with theWHEREclause is opened or theFOR EACHblock is entered.You can perhaps best think of a function as a small piece of code that performs a frequently needed calculation, or that checks a rule or does some common data transformation. In general, this is the best use for functions. However, a function can be a more complex body of code if this is appropriate.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |